home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Entertainment / MacMud / Mud 4.0 / exec.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-30  |  5.9 KB  |  146 lines  |  [TEXT/tefi]

  1. /*
  2.  * A compiled program consists of several data blocks, all allocated
  3.  * contiguos in memory to enhance the working set. At the compilation,
  4.  * the blocks will be allocated separately, as the final size is
  5.  * unknow. When compilation is done, the blocks will be copied into
  6.  * the one big area.
  7.  *
  8.  * There are 5 different blocks of information for each program:
  9.  * 1. The program itself. Consists of machine code instructions for a virtual
  10.  *    stack machine. The size of the program must not be bigger than
  11.  *    65535 bytes, as 16 bit pointers are used. Who would ever need a bigger
  12.  *    program :-)
  13.  * 2. Function names. All local functions that has been defined or called,
  14.  *    with the address of the function in the program. Inherited functions
  15.  *    will be found here too, with information of how far up the inherit
  16.  *    chain that the function was defined.
  17.  * 3. String table. All strings used in the program. They are all pointers
  18.  *    into the shared string area. Thus, they are easily found and deallocated
  19.  *    when the object is destructed.
  20.  * 4. Table of variable names. They all point into the shared string table.
  21.  * 5. Line number information. A table which tells at what address every
  22.  *    line belongs to. The table has the same number of entries as the
  23.  *    programs has source lines. This is used at errors, to find out the
  24.  *    line number of the error.
  25.  * 6. List of inherited objects.
  26.  */
  27.  
  28. /*
  29.  * When an new object inherits from another, all function definitions
  30.  * are copied, and all variable definitions.
  31.  * Flags below can't explicitly declared. Flags that can be declared,
  32.  * are found with TYPE_ below.
  33.  *
  34.  * When an object is compiled with type testing NAME_STRICT_TYPES, all
  35.  * types are saved of the arguments for that function during compilation.
  36.  * If the #pragma save_types is specified, then the types are saved even
  37.  * after compilation, to be used when the object is inherited.
  38.  */
  39. #define NAME_INHERITED        0x1    /* Defined by inheritance */
  40. #define NAME_UNDEFINED        0x2    /* Not defined yet */
  41. #define NAME_STRICT_TYPES    0x4    /* Compiled with type testing */
  42. #define NAME_HIDDEN        0x8    /* Not visible for inheritance */
  43. #define NAME_PROTOTYPE        0x10    /* Defined by a prototype only */
  44.  
  45. struct function {
  46.     char *name;
  47.     unsigned short offset;    /* Address of function,
  48.                  * or inherit table index when inherited. */
  49.     unsigned short flags;    /* NAME_ . See above. */
  50.     unsigned short num_local;    /* Number of local variables */
  51.     unsigned short num_arg;    /* Number of arguments needed.
  52.                    -1 arguments means function not defined
  53.                    in this object. Probably inherited */
  54.     unsigned short function_index_offset;
  55.     /* Used so that it is possible to quickly find this function
  56.      * in the inherited program.
  57.      */
  58.     unsigned short type;    /* Return type of function. See below. */
  59. };
  60.  
  61. struct variable {
  62.     char *name;
  63.     unsigned short type;    /* Type of variable. See below. TYPE_ */
  64.     unsigned short flags;    /* Facts found by the compiler. NAME_ */
  65. };
  66.  
  67. struct inherit {
  68.     struct program *prog;
  69.     unsigned short function_index_offset;
  70.     unsigned short variable_index_offset;
  71.     unsigned short type;
  72. };
  73.  
  74. struct program {
  75.     int ref;                /* Reference count */
  76. #ifdef DEBUG
  77.     int extra_ref;            /* Used to verify ref count */
  78. #endif
  79.     char *program;            /* The binary instructions */
  80.     char *name;                /* Name of file that defined prog */
  81.     int  id_number;            /* used to associate information with
  82.                       this prog block without needing to
  83.                        increase the reference count     */
  84.     unsigned short *line_numbers;    /* Line number information */
  85.     struct function *functions;
  86.     char **strings;            /* All strings uses by the program */
  87.     struct variable *variable_names;    /* All variables defined */
  88.     struct inherit *inherit;        /* List of inherited prgms */
  89.     int total_size;            /* Sum of all data in this struct */
  90.     int heart_beat;            /* Index of the heart beat function.
  91.                      * -1 means no heart beat
  92.                      */
  93.     /*
  94.      * The types of function arguments are saved where 'argument_types'
  95.      * points. It can be a variable number of arguments, so allocation
  96.      * is done dynamically. To know where first argument is found for
  97.      * function 'n' (number of function), use 'type_start[n]'.
  98.      * These two arrays will only be allocated if '#pragma save_types' has
  99.      * been specified. This #pragma should be specified in files that are
  100.      * commonly used for inheritance. There are several lines of code
  101.      * that depends on the type length (16 bits) of 'type_start' (sorry !).
  102.      */
  103.     unsigned short *argument_types;
  104. #define INDEX_START_NONE        65535
  105.     unsigned short *type_start;
  106.     /*
  107.      * And now some general size information.
  108.      */
  109.     unsigned short program_size;    /* size of this instruction code */
  110.     unsigned short num_functions;
  111.     unsigned short num_strings;
  112.     unsigned short num_variables;
  113.     unsigned short num_inherited;
  114. };
  115.  
  116. extern struct program *current_prog;
  117.  
  118. /*
  119.  * Types available. The number '0' is valid as any type. These types
  120.  * are only used by the compiler, when type checks are enabled. Compare with
  121.  * the run-time types, named T_ interpret.h.
  122.  */
  123.  
  124. #define TYPE_UNKNOWN    0    /* This type must be casted */
  125. #define TYPE_NUMBER    1
  126. #define TYPE_STRING    2
  127. #define TYPE_VOID    3
  128. #define TYPE_OBJECT    4
  129. #define TYPE_ANY    5    /* Will match any type */
  130. #define TYPE_MAPPING    6
  131.  
  132. /*
  133.  * These are or'ed in on top of the basic type.
  134.  */
  135. #define TYPE_MOD_STATIC        0x0100    /* Static function or variable */
  136. #define TYPE_MOD_NO_MASK    0x0200    /* The nomask => not redefineable */
  137. #define TYPE_MOD_POINTER    0x0400    /* Pointer to a basic type */
  138. #define TYPE_MOD_PRIVATE    0x0800    /* Can't be inherited */
  139. #define TYPE_MOD_PROTECTED    0x1000
  140. #define TYPE_MOD_PUBLIC        0x2000  /* Force inherit through private */
  141. #define TYPE_MOD_VARARGS    0x4000    /* Used for type checking */
  142.  
  143. #define TYPE_MOD_MASK        (~(TYPE_MOD_STATIC | TYPE_MOD_NO_MASK |\
  144.                    TYPE_MOD_PRIVATE | TYPE_MOD_PROTECTED |\
  145.                    TYPE_MOD_PUBLIC | TYPE_MOD_VARARGS))
  146.